﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GUIScript : MonoBehaviour {

    public static int Generation = 0;
    public static int MaxGenerations = 0;
    public static int Creature = 0;
    public static int NumberCreatures = 0;
    public static float LastFitness = 0;

    public static List<GenerationInfo> Info = new List<GenerationInfo>();

    void OnGUI()
    {
        // Stat box
        GUILayout.BeginArea(new Rect(Screen.width - 150, 0, 150, 150), "box");
        GUILayout.BeginVertical("box");
        GUILayout.Label("Stats");
        GUILayout.Label("Generation: " + Generation + "/" + MaxGenerations);
        GUILayout.Label("Gene: " + Creature + "/" + NumberCreatures);
        GUILayout.Label("Last fitness: " + LastFitness.ToString("0.00"));
        GUILayout.EndVertical();
        GUILayout.EndArea();
        // End stat box

        // Generation box

        GUILayout.BeginVertical("box");
        GUILayout.Label("Generation info");

        int index = (Info.Count < 10) ? Info.Count : 10;

        for (int i = index; i > 0; i--)
        {
            GUILayout.Label(Info[Info.Count - i].Generation + ": Min=" + Info[Info.Count - i].MinFitness.ToString("0.00") + ", Avg=" + Info[Info.Count - i].AverageFitness.ToString("0.00") + ", Max=" + Info[Info.Count - i].MaxFitness.ToString("0.00") + " - Bad Genes: " + Info[Info.Count - i].BadGenes);
        }
        GUILayout.EndVertical();

        if (Manager.Instance.State != ManagerState.Evolution)
        {
            if (GUILayout.Button("YES"))
            {
                Manager.Instance.Pick = PlayerPick.Yes;
            }
            if (GUILayout.Button("NO"))
            {
                Manager.Instance.Pick = PlayerPick.No;
            }

            if (Manager.Instance.State != ManagerState.Controllable)
            {
                if (GUILayout.Button("TRY"))
                {
                    Manager.Instance.ControllableEvent(true);
                    Manager.Instance.State = ManagerState.Controllable;
                }
            }
            else
            {
                if (GUILayout.Button("WATCH IT"))
                {
                    Manager.Instance.ControllableEvent(false);
                    Manager.Instance.State = ManagerState.PlayerChoice;
                }
            }
        }

        // End generation box
    }

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

public class GenerationInfo
{
    public int Generation { get; set; }
    public float AverageFitness { get; set; }
    public float MaxFitness { get; set; }
    public float MinFitness { get; set; }
    public int BadGenes { get; set; }
}